package org.demo.szml.loggingservice.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.demo.szml.loggingservice.repository.ILoggingRepository;
import org.demo.szml.loggingservice.repository.mapper.OperationLogsMapper;
import org.demo.szml.loggingservice.repository.po.OperationLogsPO;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @description: 日志仓储服务实现类
 * @date: 2025/6/16 15:06
 * @version: 1.0
 */
@Service
public class LoggingRepositoryImpl implements ILoggingRepository {

    private final OperationLogsMapper operationLogsMapper;

    public LoggingRepositoryImpl(OperationLogsMapper operationLogsMapper){
        this.operationLogsMapper = operationLogsMapper;
    }


    @Override
    public void saveOperationLog(OperationLogsPO po) {
        OperationLogsPO dbPo = operationLogsMapper.selectOne(new LambdaQueryWrapper<OperationLogsPO>()
                .select(OperationLogsPO::getLogId).eq(OperationLogsPO::getLogId, po.getLogId()));
        if(Objects.nonNull(dbPo)){
            return;
        }
        operationLogsMapper.insert(po);
    }
}
